<script>
    let obj = {
        name: "哈哈",
        age: 100,
        sex: "娜"
    }


    Object.prototype[Symbol.iterator] = function () {
        let datas = Object.values(this);  //获取对象所有的属性值，以一个数组的形式返回
        let index = 0;
        return {
            next() {
                if (index >= datas.length) {
                    return { value: datas[index++], done: true };
                } else {
                    return { value: datas[index++], done: false }
                }
            }
        }
    }

    // console.log(obj[Symbol.iterator]); // 函数 
    // console.log(obj[Symbol.iterator]());  //调用


    // let iter = obj[Symbol.iterator]();
    // console.log(iter);

    // console.log(iter.next());
    // console.log(iter.next());
    // console.log(iter.next());
    // console.log(iter.next());


    for (let val of obj) {
        console.log(val);
    }

    let obj1 = { name: "a", age: 1, sex: 2, hobby: 3 };
    for (let val of obj1) {
        console.log(val);
    }

</script>